﻿using IotContract.Dtos.Clients;
using IotContract.Dtos.Remotes.Request;
using IotContract.Dtos.Servers.Process;
using IotContract.Dtos.Servers.Process.F29;
using IotContract.Dtos.Servers.Pushs;
using IotContract.Enums;
using IotContract.Interfaces.Process;
using IotContract.Models.Clients.Hks;

using IotContract.Models.Jobs.F29;
using IotContract.Models.Process;
using IotContract.Models.Process.F29;
using IotContract.Models.Writes.F29;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using XT.Common.Models.Server;

namespace F29ServerProcess.Interfaces;
/// <summary>
/// 数据仓
/// </summary>
public interface IProcessDataService
{
   
    /// <summary>
    /// 推送的扫码枪
    /// </summary>
    /// <returns></returns>
    ConcurrentDictionary<string, List<PushBcrDto>> Bcrs { get; set; }
    /// <summary>
    /// 物流线数据
    /// </summary>
    ConcurrentDictionary<int, F29CvUnitDto> CvUnitTags { get; set; }

    /// <summary>
    /// 堆垛机数据
    /// </summary>
    ConcurrentDictionary<string, F29ScUnitDto> ScUnits { get; set; }
    /// <summary>
    /// 拘束机数据
    /// </summary>
    ConcurrentDictionary<string, F29RestraintUnitDto> RestraintUnits { get; set; }
    /// <summary>
    /// 换盘机数据
    /// </summary>
    ConcurrentDictionary<string,F29CebUnitDto> CebUnits { get; set; }
    /// <summary>
    /// 插钉机数据
    /// </summary>
    ConcurrentDictionary<string, F29PinInUnitDto> PinInUnits { get; set; }
    /// <summary>
    /// 拔钉机数据
    /// </summary>
    ConcurrentDictionary<string, F29PinOutUnitDto> PinOutUnits { get; set; }
    /// <summary>
    /// 充放电数据
    /// </summary>
    ConcurrentDictionary<string,F29ProcessFmtData> Fmts { get; set; }
    /// <summary>
    /// 缓存维护托盘和任务
    /// </summary>
    /// <param name="unit"></param>
    void SetTrayByTask(F29CvUnitDto unit);

    /// <summary>
    /// 清除tag提交信息
    /// </summary>
    /// <param name="unit"></param>
    void ClearTag(F29CvUnitDto unit);
    /// <summary>
    /// 获取入库站台类型
    /// </summary>
    /// <param name="tagNum"></param>
    /// <returns>0非入库站台  1单叉站台  2双叉前站台  3双叉后站台</returns>
    int GetUnitTagType(int tagNum);
    /// <summary>
    /// 获取另外的入库站台
    /// </summary>
    /// <param name="tagNum"></param>
    /// <returns></returns>
    F29CvUnitDto? GetEnterOtherTag(int tagNum);
    /// <summary>
    /// 写入物流线
    /// </summary>
    /// <param name="trayResponse"></param>
    /// <returns></returns>
    Task<bool> WriteCv(CvTrayTask trayResponse);
    /// <summary>
    /// 写入物流线状态
    /// </summary>
    /// <param name="trayResponse"></param>
    /// <returns></returns>
    Task<bool> WriteCvStatus(int tagNumber, int value);
    /// <summary>
    /// 写入堆垛机-启动
    /// </summary>
    /// <param name="write"></param>
    /// <param name="equipNum"></param>
    /// <returns></returns>
    Task<bool> WriteSCToRun(F29ScPlcWrite write, string equipNum);
    /// <summary>
    /// 写入扫码枪
    /// </summary>
    /// <param name="bcrId"></param>
    /// <param name="equipId"></param>
    /// <returns></returns>
    Task<bool> WriteBcr(string bcrId, long equipId);


    /// <summary>
    /// 添加报警信息
    /// </summary>
    /// <param name="warns"></param>
    /// <returns></returns>
    Task<bool> AddWarns(IEnumerable<IotEquipWarnDto> warns);
    /// <summary>
    /// 写入堆垛机-完成
    /// </summary>
    /// <param name="equipNum"></param>
    /// <returns></returns>
    Task<bool> WriteSCToComplete(string equipNum);
    /// <summary>
    /// 写入拘束机
    /// </summary>
    /// <param name="tagProperty"></param>
    /// <param name="equipNum"></param>
    /// <returns></returns>
    Task<bool> WriteRestraint(string tagProperty, string equipNum,string value="1");

    /// <summary>
    /// 写入换盘机
    /// </summary>
    /// <param name="tagProperty"></param>
    /// <param name="value"></param>
    /// <param name="equipNum"></param>
    /// <returns></returns>
    Task<bool> WriteCeb(string tagProperty, string value, string equipNum);


    /// <summary>
    /// 写入拔钉机
    /// </summary>
    /// <param name="tagProperty"></param>
    /// <param name="equipNum"></param>
    /// <returns></returns>
    Task<bool> WritePinOut(string tagProperty, string equipNum);

    #region 远程调用

    /// <summary>
    /// 验证换盘进入
    /// </summary>
    /// <param name="fmsTray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> ValidateCebEnterTray(FmsTrayRequest fmsTray);

    /// <summary>
    /// 获取通道
    /// </summary>
    /// <param name="fmsTray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<List<FMTCell>>> GetCebChannel(FmsTrayRequest fmsTray);

    /// <summary>
    /// 换盘结束通知
    /// </summary>
    /// <param name="fmsTray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> CebWorkDoneInform(FmsTrayRequest fmsTray);

    /// <summary>
    /// 验证换盘出去
    /// </summary>
    /// <param name="fmsTray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> ValidateCebOutTray(FmsTrayRequest fmsTray);
    
    /// <summary>
    /// 验证托盘
    /// </summary>
    /// <param name="equipNum"></param>
    /// <param name="equipType"></param>
    /// <param name="tray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> ValidateEnterTray(string equipNum,IotEquipType equipType,string tray);
    /// <summary>
    /// 验证托盘出去
    /// </summary>
    /// <param name="equipNum"></param>
    /// <param name="equipType"></param>
    /// <param name="tray"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> ValidateOutTray(string equipNum, IotEquipType equipType, string tray);
    /// <summary>
    /// 提交叠盘完成
    /// </summary>
    /// <param name="tagNumber"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> CommitStackOver(int tagNumber);

    /// <summary>
    /// 扫描后提交托盘
    /// </summary>
    /// <param name="unit"></param>
    /// <returns></returns>
    Task<AdminCodeResult<CvTrayTask>> CommitTrays(F29CvUnitDto unit);

    /// <summary>
    /// 扫码后入库站台提交
    /// </summary>
    /// <param name="unit2"></param>
    /// <param name="unit1"></param>
    /// <returns></returns>
    Task<AdminCodeResult<F29EnterJob>> CommitEnterTrays(F29CvUnitDto unit2, F29CvUnitDto unit1);

    /// <summary>
    /// 任务完成
    /// </summary>
    /// <param name="jobId"></param>
    /// <returns></returns>
    Task<AdminCodeResult<string>> CompleteJob(string jobId, string jobId2);
    /// <summary>
    /// 执行相关业务
    /// </summary>
    /// <param name="job"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    Task ExecuteData(ProcessBaseData job, ProcessProviderType type);

   

    #endregion

    /// <summary>
    /// 初始化数据
    /// </summary>
    /// <returns></returns>
    Task IniData();
    Task<bool> WritePinIn(string v, string equipNum);
    /// <summary>
    /// 获取所有数据
    /// </summary>
    /// <returns></returns>
    List<F29ProcessData> GetAllEquips();
}
